//
//  MADareChoiceView.m
//  MateAdv
//
//  Created by 茶 on 2023/9/14.
//

#import "MADareChoiceView.h"

@interface MADareChoiceView ()

@property (nonatomic, strong) UIButton *upBtn;
@property (nonatomic, strong) UIButton *downBtn;

@end

@implementation MADareChoiceView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self initInterface];
    }
    return self;
}

- (void)initInterface {
    _upBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _upBtn.tag = 0;
    [_upBtn setBackgroundImage:[UIImage imageNamed:@"Dare_Up"] forState:UIControlStateNormal];
    [_upBtn addTarget:self action:@selector(buttonEventWithButton:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_upBtn];
    [_upBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.ma_offset(403);
        make.top.ma_offset(-403);
    }];
    
    UIImageView *upTitleView = [UIImageView initWithName:@"Dare_Truth_0"];
    upTitleView.userInteractionEnabled = NO;
    [_upBtn addSubview:upTitleView];
    [upTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.ma_offset(99);
        make.left.ma_offset(34);
    }];
    
    UILabel *upLable = [UILabel new];
    upLable.userInteractionEnabled = NO;
    upLable.text = @"真心话";
    upLable.textColor = UIColor.whiteColor;
    upLable.font = MAFontScaleSemibold(50);
    [_upBtn addSubview:upLable];
    [upLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.ma_offset(142);
        make.left.ma_offset(32);
    }];
    
    UIImageView *upImgView = [UIImageView initWithName:@"Dare_Truth_1"];
    upImgView.userInteractionEnabled = NO;
    [_upBtn addSubview:upImgView];
    [upImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.ma_offset(209);
        make.left.ma_offset(27);
    }];
    
    _downBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _downBtn.tag = 1;
    [_downBtn setBackgroundImage:[UIImage imageNamed:@"Dare_Down"] forState:UIControlStateNormal];
    [_downBtn addTarget:self action:@selector(buttonEventWithButton:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_downBtn];
    [_downBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.ma_offset(403);
        make.bottom.ma_offset(403);
    }];
    
    UIImageView *downTitleView = [UIImageView initWithName:@"Dare_Dare_0"];
    downTitleView.userInteractionEnabled = NO;
    [_downBtn addSubview:downTitleView];
    [downTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.ma_offset(-34);
        make.bottom.ma_offset(-88);
    }];
    
    UILabel *downLable = [UILabel new];
    downLable.userInteractionEnabled = NO;
    downLable.text = @"大冒险";
    downLable.textColor = UIColor.whiteColor;
    downLable.font = MAFontScaleSemibold(50);
    [_downBtn addSubview:downLable];
    [downLable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.ma_offset(-132);
        make.right.ma_offset(-32);
    }];
    
    UIImageView *downImgView = [UIImageView initWithName:@"Dare_Dare_1"];
    downImgView.userInteractionEnabled = NO;
    [_downBtn addSubview:downImgView];
    [downImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.ma_offset(-192);
        make.right.ma_offset(-27);
    }];
    
    [self layoutIfNeeded];
}

- (void)buttonEventWithButton:(UIButton *)button {
    MABlock(self.choiceBlock, button.tag);
    [self endAnimation];
}


- (void)beginAnimation {
    MAWeakify(self);
    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        MAStrongify(self);
        [self.upBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.ma_offset(0);
        }];
        [self.downBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.ma_offset(0);
        }];
        [self layoutIfNeeded];
    } completion:^(BOOL finished) {
//        MAStrongify(self);
    }];
}


- (void)endAnimation {
    MAWeakify(self);
    [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        MAStrongify(self);
        [self.upBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.ma_offset(-403);
        }];
        [self.downBtn mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.ma_offset(403);
        }];
        [self layoutIfNeeded];
    } completion:^(BOOL finished) {
        MAStrongify(self);
        [self removeFromSuperview];
    }];
}

@end
